#pragma once
#ifndef __G_SCOPED_LOCK_H__
#define __G_SCOPED_LOCK_H__

#include "GSpinMutex.h"

namespace GThread
{
	template <typename T>
	class GScopedLock
	{

	};

	template <>
	class GScopedLock <GSpinMutex>
	{
	private:
		bool Locked;
		GSpinMutex*	Lock;

	public:
		GScopedLock(GSpinMutex& TheLock)
		{
			Locked = false;
			Lock = &TheLock;
		}

		~GScopedLock()
		{
			Free();
		}

		bool TryAcquire()
		{
			if (!Locked)
			{
				Locked = Lock->TryAcquire();
			}
			return Locked;
		}

		void Acquire()
		{
			Lock->Acquire();
			Locked = true;
		}

		void Free()
		{
			if (Locked)
			{
				Lock->Free();
				Locked = false;
			}
		}
	};

}

#endif